const Web3 = require('web3');
let WEB3;
let Address;
let Contracts;
let ContractAddr = "0x6Da47D318bf1eEC3DDaD6fec93F8ADE2fA6e0Ca6";

const Ballot = [
	{
		"inputs": [],
		"name": "CreatePlayer",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "string",
				"name": "content",
				"type": "string"
			},
			{
				"internalType": "string[]",
				"name": "option",
				"type": "string[]"
			},
			{
				"internalType": "uint256",
				"name": "Validity",
				"type": "uint256"
			},
			{
				"internalType": "address",
				"name": "addr",
				"type": "address"
			}
		],
		"name": "InitiateEvent",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "id",
				"type": "uint256"
			},
			{
				"internalType": "uint256",
				"name": "option",
				"type": "uint256"
			}
		],
		"name": "Report",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "id",
				"type": "uint256"
			}
		],
		"name": "Reward",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "id",
				"type": "uint256"
			},
			{
				"internalType": "uint256",
				"name": "option",
				"type": "uint256"
			},
			{
				"internalType": "uint256",
				"name": "finance",
				"type": "uint256"
			}
		],
		"name": "Vote",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "id",
				"type": "uint256"
			}
		],
		"name": "getEvent",
		"outputs": [
			{
				"components": [
					{
						"internalType": "uint256",
						"name": "ID",
						"type": "uint256"
					},
					{
						"internalType": "address",
						"name": "Sponsor",
						"type": "address"
					},
					{
						"internalType": "string",
						"name": "Content",
						"type": "string"
					},
					{
						"internalType": "string[]",
						"name": "Option",
						"type": "string[]"
					},
					{
						"internalType": "address",
						"name": "Reporter",
						"type": "address"
					},
					{
						"internalType": "uint256",
						"name": "StartDate",
						"type": "uint256"
					},
					{
						"internalType": "uint256",
						"name": "Deadline",
						"type": "uint256"
					},
					{
						"internalType": "address[]",
						"name": "Voters",
						"type": "address[]"
					},
					{
						"internalType": "uint256",
						"name": "PrizePool",
						"type": "uint256"
					},
					{
						"internalType": "bool",
						"name": "Report",
						"type": "bool"
					},
					{
						"internalType": "uint256",
						"name": "Result",
						"type": "uint256"
					}
				],
				"internalType": "struct Ballot.Event",
				"name": "",
				"type": "tuple"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "id",
				"type": "uint256"
			},
			{
				"internalType": "uint256",
				"name": "option",
				"type": "uint256"
			}
		],
		"name": "getEventOptionInfo",
		"outputs": [
			{
				"internalType": "uint256",
				"name": "",
				"type": "uint256"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "addr",
				"type": "address"
			}
		],
		"name": "getPlayer",
		"outputs": [
			{
				"internalType": "uint256",
				"name": "",
				"type": "uint256"
			},
			{
				"internalType": "uint256[]",
				"name": "",
				"type": "uint256[]"
			},
			{
				"internalType": "uint256[]",
				"name": "",
				"type": "uint256[]"
			},
			{
				"internalType": "uint256[]",
				"name": "",
				"type": "uint256[]"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "addr",
				"type": "address"
			}
		],
		"name": "getPlayerLogs",
		"outputs": [
			{
				"components": [
					{
						"internalType": "uint256",
						"name": "Time",
						"type": "uint256"
					},
					{
						"internalType": "uint256",
						"name": "ID",
						"type": "uint256"
					},
					{
						"internalType": "string",
						"name": "action",
						"type": "string"
					},
					{
						"internalType": "int256",
						"name": "Change",
						"type": "int256"
					},
					{
						"internalType": "uint256",
						"name": "Balance",
						"type": "uint256"
					}
				],
				"internalType": "struct Ballot.Log[]",
				"name": "",
				"type": "tuple[]"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [],
		"name": "getTotalEvent",
		"outputs": [
			{
				"internalType": "uint256",
				"name": "",
				"type": "uint256"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "id",
				"type": "uint256"
			},
			{
				"internalType": "address",
				"name": "addr",
				"type": "address"
			}
		],
		"name": "getVote",
		"outputs": [
			{
				"components": [
					{
						"internalType": "bool",
						"name": "Voted",
						"type": "bool"
					},
					{
						"internalType": "uint256",
						"name": "Time",
						"type": "uint256"
					},
					{
						"internalType": "uint256",
						"name": "Option",
						"type": "uint256"
					},
					{
						"internalType": "uint256",
						"name": "Finance",
						"type": "uint256"
					},
					{
						"internalType": "bool",
						"name": "Reward",
						"type": "bool"
					}
				],
				"internalType": "struct Ballot.Option",
				"name": "",
				"type": "tuple"
			}
		],
		"stateMutability": "view",
		"type": "function"
	}
];

// WEB3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/v3/a400c585da084233b12bb66f23304eb6'));
// Contracts = new WEB3.eth.Contract(Ballot, ContractAddr);

function Connection() {
	console.log(Web3);
	console.log(ethereum.networkVersion);
	if (typeof web3 !== 'undefined') {
		if (ethereum.selectedAddress !== 'undefined') {
			console.log(ethereum.selectedAddress);
			if (ethereum.networkVersion === '5777') {
				WEB3 = new Web3(web3.currentProvider);
				ethereum.enable();
				Address = ethereum.selectedAddress;
				Contracts = new WEB3.eth.Contract(Ballot, ContractAddr);
				console.log(Contracts);
				// Contracts.methods.CreatePlayer().send({ from: Address }).then(res=>{
				// 	console.log(res);
				// });
			} else {
				alert("请选择Ropsten测试网络！");
			}
		} else {
			alert("请解锁MetaMask并创建账号！");
		}
	} else {
		alert("请在浏览器安装MetaMask插件！");
	}
	return WEB3;
}


// _web3.eth.defaultAccount = web3.eth.accounts[1];
// ethereum.enable();
// ethereum.selectedAddress;
// window.console.log(ethereum.selectedAddress);
// window.addr = ethereum.selectedAddress;

function shang() {
	WEB3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545'));
	console.log('上链操作');
	Contracts = new WEB3.eth.Contract(Ballot);
	console.log(Contracts);
	let data="0x608060405234801561001057600080fd5b50613d9f806100206000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80636bbb2afb116100715780636bbb2afb146101535780636d1884e01461016f578063ab05f2ce1461019f578063bc3f931f146101cf578063c2351d65146101ff578063ca4571e81461022f576100a9565b806331f46380146100ae5780633ac0594a146100ca5780635c12cd4b146100e65780635cb9c5f2146101195780636756f66014610137575b600080fd5b6100c860048036038101906100c39190612acf565b610239565b005b6100e460048036038101906100df9190612b6e565b6108ec565b005b61010060048036038101906100fb9190612aa2565b610f27565b6040516101109493929190613532565b60405180910390f35b61012161113c565b60405161012e9190613517565b60405180910390f35b610151600480360381019061014c9190612bdb565b611148565b005b61016d60048036038101906101689190612c1b565b611547565b005b61018960048036038101906101849190612b6e565b611d6e565b60405161019691906134da565b60405180910390f35b6101b960048036038101906101b49190612bdb565b61209d565b6040516101c69190613517565b60405180910390f35b6101e960048036038101906101e49190612b9b565b6120cf565b6040516101f691906134fc565b60405180910390f35b61021960048036038101906102149190612aa2565b612191565b60405161022691906132d8565b60405180910390f35b6102376122e9565b005b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610309576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103009061331a565b60405180910390fd5b600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146103d9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103d0906133ba565b60405180910390fd5b60006101f4905080600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101541015610465576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161045c906133fa565b60405180910390fd5b80600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010160008282546104b79190613894565b925050819055506000808054905090506060600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600201829080600181540180825580915050600190039060005260206000200160009091909190915055600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060040182908060018154018082558091505060019003906000526020600020016000909190919091505560006040518061016001604052808481526020013373ffffffffffffffffffffffffffffffffffffffff1681526020018981526020018881526020018673ffffffffffffffffffffffffffffffffffffffff1681526020014281526020018742610605919061371f565b815260200183815260200160008152602001600015158152602001606381525090806001815401808255809150506001900390600052602060002090600b02016000909190919091506000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020190805190602001906106bb929190612653565b5060608201518160030190805190602001906106d89291906126d9565b5060808201518160040160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060a0820151816005015560c0820151816006015560e0820151816007019080519060200190610750929190612739565b5061010082015181600801556101208201518160090160006101000a81548160ff02191690831515021790555061014082015181600a01555050600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060a001604052804281526020018481526020016040518060400160405280600d81526020017f496e6974696174654576656e740000000000000000000000000000000000000081525081526020018560006108289190613800565b8152602001600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101548152509080600181540180825580915050600190039060005260206000209060050201600090919091909150600082015181600001556020820151816001015560408201518160020190805190602001906108cc929190612653565b506060820151816003015560808201518160040155505050505050505050565b60011515600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600501600083815260200190815260200160002060000160009054906101000a900460ff16151514610996576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161098d9061339a565b60405180910390fd5b60011515600082815481106109ae576109ad613a4c565b5b90600052602060002090600b020160090160009054906101000a900460ff16151514610a0f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a06906134ba565b60405180910390fd5b60008181548110610a2357610a22613a4c565b5b90600052602060002090600b0201600a0154600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060050160008381526020019081526020016000206002015414610acc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ac39061341a565b60405180910390fd5b60001515600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600501600083815260200190815260200160002060040160009054906101000a900460ff16151514610b76576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b6d9061335a565b60405180910390fd5b6000600160008381526020019081526020016000206000016000808481548110610ba357610ba2613a4c565b5b90600052602060002090600b0201600a0154815260200190815260200160002054600160008481526020019081526020016000206000016000808581548110610bef57610bee613a4c565b5b90600052602060002090600b0201600a015481526020019081526020016000205460008481548110610c2457610c23613a4c565b5b90600052602060002090600b020160080154610c409190613894565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600501600085815260200190815260200160002060030154610ca191906137a6565b610cab9190613775565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600501600084815260200190815260200160002060030154610d0c919061371f565b905080600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001016000828254610d60919061371f565b925050819055506001600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600501600084815260200190815260200160002060040160006101000a81548160ff021916908315150217905550600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060a001604052804281526020018481526020016040518060400160405280600681526020017f52657761726400000000000000000000000000000000000000000000000000008152508152602001838152602001600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154815250908060018154018082558091505060019003906000526020600020906005020160009091909190915060008201518160000155602082015181600101556040820151816002019080519060200190610f0c929190612653565b50606082015181600301556080820151816004015550505050565b60006060806060600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600301600360008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600201600360008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206004018280548060200260200160405190810160405280929190818152602001828054801561108257602002820191906000526020600020905b81548152602001906001019080831161106e575b50505050509250818054806020026020016040519081016040528092919081815260200182805480156110d457602002820191906000526020600020905b8154815260200190600101908083116110c0575b505050505091508080548060200260200160405190810160405280929190818152602001828054801561112657602002820191906000526020600020905b815481526020019060010190808311611112575b5050505050905093509350935093509193509193565b60008080549050905090565b600080549050821061118f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111869061345a565b60405180910390fd5b600082815481106111a3576111a2613a4c565b5b90600052602060002090600b02016003018054905081106111f9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111f09061343a565b60405180910390fd5b600015156000838154811061121157611210613a4c565b5b90600052602060002090600b020160090160009054906101000a900460ff16151514611272576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112699061333a565b60405180910390fd5b6000828154811061128657611285613a4c565b5b90600052602060002090600b0201600601544210156112da576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112d19061337a565b60405180910390fd5b600082815481106112ee576112ed613a4c565b5b90600052602060002090600b020160040160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461138d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611384906132fa565b60405180910390fd5b80600083815481106113a2576113a1613a4c565b5b90600052602060002090600b0201600a01819055506001600083815481106113cd576113cc613a4c565b5b90600052602060002090600b020160090160006101000a81548160ff021916908315150217905550600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060a001604052804281526020018481526020016040518060400160405280600681526020017f5265706f72740000000000000000000000000000000000000000000000000000815250815260200160008152602001600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001015481525090806001815401808255809150506001900390600052602060002090600502016000909190919091506000820151816000015560208201518160010155604082015181600201908051906020019061152c929190612653565b50606082015181600301556080820151816004015550505050565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611617576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161160e9061331a565b60405180910390fd5b600080549050831061165e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116559061345a565b60405180910390fd5b6000838154811061167257611671613a4c565b5b90600052602060002090600b02016003018054905082106116c8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116bf9061343a565b60405180910390fd5b600083815481106116dc576116db613a4c565b5b90600052602060002090600b020160060154421061172f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117269061349a565b60405180910390fd5b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101548111156117b4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117ab906133fa565b60405180910390fd5b60001515600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600501600085815260200190815260200160002060000160009054906101000a900460ff161515146118bc57600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060050160008481526020019081526020016000206002015482146118bb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016118b2906133da565b60405180910390fd5b5b80600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101600082825461190e9190613894565b92505081905550600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060030183908060018154018082558091505060019003906000526020600020016000909190919091505542600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060050160008581526020019081526020016000206001018190555081600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060050160008581526020019081526020016000206002018190555080600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060050160008581526020019081526020016000206003016000828254611a9a919061371f565b925050819055506001600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600501600085815260200190815260200160002060000160006101000a81548160ff02191690831515021790555060008381548110611b2457611b23613a4c565b5b90600052602060002090600b0201600701339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060008481548110611bab57611baa613a4c565b5b90600052602060002090600b02016008016000828254611bcb919061371f565b92505081905550806001600085815260200190815260200160002060000160008481526020019081526020016000206000828254611c09919061371f565b92505081905550600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060a001604052804281526020018581526020016040518060400160405280600481526020017f566f7465000000000000000000000000000000000000000000000000000000008152508152602001836000611cae9190613800565b8152602001600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154815250908060018154018082558091505060019003906000526020600020906005020160009091909190915060008201518160000155602082015181600101556040820151816002019080519060200190611d52929190612653565b5060608201518160030155608082015181600401555050505050565b611d766127c3565b60008281548110611d8a57611d89613a4c565b5b90600052602060002090600b020160405180610160016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600282018054611e149061395c565b80601f0160208091040260200160405190810160405280929190818152602001828054611e409061395c565b8015611e8d5780601f10611e6257610100808354040283529160200191611e8d565b820191906000526020600020905b815481529060010190602001808311611e7057829003601f168201915b5050505050815260200160038201805480602002602001604051908101604052809291908181526020016000905b82821015611f67578382906000526020600020018054611eda9061395c565b80601f0160208091040260200160405190810160405280929190818152602001828054611f069061395c565b8015611f535780601f10611f2857610100808354040283529160200191611f53565b820191906000526020600020905b815481529060010190602001808311611f3657829003601f168201915b505050505081526020019060010190611ebb565b5050505081526020016004820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200160058201548152602001600682015481526020016007820180548060200260200160405190810160405280929190818152602001828054801561205e57602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019060010190808311612014575b50505050508152602001600882015481526020016009820160009054906101000a900460ff16151515158152602001600a820154815250509050919050565b600060016000848152602001908152602001600020600001600083815260200190815260200160002054905092915050565b6120d761284b565b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060050160008481526020019081526020016000206040518060a00160405290816000820160009054906101000a900460ff161515151581526020016001820154815260200160028201548152602001600382015481526020016004820160009054906101000a900460ff161515151581525050905092915050565b6060600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805480602002602001604051908101604052809291908181526020016000905b828210156122de57838290600052602060002090600502016040518060a001604052908160008201548152602001600182015481526020016002820180546122399061395c565b80601f01602080910402602001604051908101604052809291908181526020018280546122659061395c565b80156122b25780601f10612287576101008083540402835291602001916122b2565b820191906000526020600020905b81548152906001019060200180831161229557829003601f168201915b5050505050815260200160038201548152602001600482015481525050815260200190600101906121f2565b505050509050919050565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156123ba576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123b19061347a565b60405180910390fd5b6060600061271090506000600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050338160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508181600101819055508281600201908051906020019061246a92919061287e565b508281600301908051906020019061248392919061287e565b508281600401908051906020019061249c92919061287e565b506002339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060a00160405280428152602001600081526020016040518060400160405280600c81526020017f437265617465506c6179657200000000000000000000000000000000000000008152508152602001848152602001600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154815250908060018154018082558091505060019003906000526020600020906005020160009091909190915060008201518160000155602082015181600101556040820151816002019080519060200190612637929190612653565b5060608201518160030155608082015181600401555050505050565b82805461265f9061395c565b90600052602060002090601f01602090048101928261268157600085556126c8565b82601f1061269a57805160ff19168380011785556126c8565b828001600101855582156126c8579182015b828111156126c75782518255916020019190600101906126ac565b5b5090506126d591906128cb565b5090565b828054828255906000526020600020908101928215612728579160200282015b82811115612727578251829080519060200190612717929190612653565b50916020019190600101906126f9565b5b50905061273591906128e8565b5090565b8280548282559060005260206000209081019282156127b2579160200282015b828111156127b15782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555091602001919060010190612759565b5b5090506127bf91906128cb565b5090565b60405180610160016040528060008152602001600073ffffffffffffffffffffffffffffffffffffffff1681526020016060815260200160608152602001600073ffffffffffffffffffffffffffffffffffffffff16815260200160008152602001600081526020016060815260200160008152602001600015158152602001600081525090565b6040518060a001604052806000151581526020016000815260200160008152602001600081526020016000151581525090565b8280548282559060005260206000209081019282156128ba579160200282015b828111156128b957825182559160200191906001019061289e565b5b5090506128c791906128cb565b5090565b5b808211156128e45760008160009055506001016128cc565b5090565b5b8082111561290857600081816128ff919061290c565b506001016128e9565b5090565b5080546129189061395c565b6000825580601f1061292a5750612949565b601f01602090049060005260206000209081019061294891906128cb565b5b50565b600061295f61295a846135b1565b61358c565b9050808382526020820190508285602086028201111561298257612981613aaf565b5b60005b858110156129d057813567ffffffffffffffff8111156129a8576129a7613aaa565b5b8086016129b58982612a5f565b85526020850194506020840193505050600181019050612985565b5050509392505050565b60006129ed6129e8846135dd565b61358c565b905082815260208101848484011115612a0957612a08613ab4565b5b612a1484828561391a565b509392505050565b600081359050612a2b81613d3b565b92915050565b600082601f830112612a4657612a45613aaa565b5b8135612a5684826020860161294c565b91505092915050565b600082601f830112612a7457612a73613aaa565b5b8135612a848482602086016129da565b91505092915050565b600081359050612a9c81613d52565b92915050565b600060208284031215612ab857612ab7613abe565b5b6000612ac684828501612a1c565b91505092915050565b60008060008060808587031215612ae957612ae8613abe565b5b600085013567ffffffffffffffff811115612b0757612b06613ab9565b5b612b1387828801612a5f565b945050602085013567ffffffffffffffff811115612b3457612b33613ab9565b5b612b4087828801612a31565b9350506040612b5187828801612a8d565b9250506060612b6287828801612a1c565b91505092959194509250565b600060208284031215612b8457612b83613abe565b5b6000612b9284828501612a8d565b91505092915050565b60008060408385031215612bb257612bb1613abe565b5b6000612bc085828601612a8d565b9250506020612bd185828601612a1c565b9150509250929050565b60008060408385031215612bf257612bf1613abe565b5b6000612c0085828601612a8d565b9250506020612c1185828601612a8d565b9150509250929050565b600080600060608486031215612c3457612c33613abe565b5b6000612c4286828701612a8d565b9350506020612c5386828701612a8d565b9250506040612c6486828701612a8d565b9150509250925092565b6000612c7a8383612cc6565b60208301905092915050565b6000612c928383612e99565b905092915050565b6000612ca683836131dc565b905092915050565b6000612cba83836132ba565b60208301905092915050565b612ccf816138c8565b82525050565b6000612ce08261364e565b612cea81856136b9565b9350612cf58361360e565b8060005b83811015612d26578151612d0d8882612c6e565b9750612d1883613685565b925050600181019050612cf9565b5085935050505092915050565b6000612d3e82613659565b612d4881856136ca565b935083602082028501612d5a8561361e565b8060005b85811015612d965784840389528151612d778582612c86565b9450612d8283613692565b925060208a01995050600181019050612d5e565b50829750879550505050505092915050565b6000612db382613664565b612dbd81856136db565b935083602082028501612dcf8561362e565b8060005b85811015612e0b5784840389528151612dec8582612c9a565b9450612df78361369f565b925060208a01995050600181019050612dd3565b50829750879550505050505092915050565b6000612e288261366f565b612e3281856136ec565b9350612e3d8361363e565b8060005b83811015612e6e578151612e558882612cae565b9750612e60836136ac565b925050600181019050612e41565b5085935050505092915050565b612e84816138da565b82525050565b612e93816138e6565b82525050565b6000612ea48261367a565b612eae81856136fd565b9350612ebe818560208601613929565b612ec781613ac3565b840191505092915050565b6000612edf60158361370e565b9150612eea82613ad4565b602082019050919050565b6000612f0260138361370e565b9150612f0d82613afd565b602082019050919050565b6000612f2560118361370e565b9150612f3082613b26565b602082019050919050565b6000612f48601c8361370e565b9150612f5382613b4f565b602082019050919050565b6000612f6b60158361370e565b9150612f7682613b78565b602082019050919050565b6000612f8e60118361370e565b9150612f9982613ba1565b602082019050919050565b6000612fb160188361370e565b9150612fbc82613bca565b602082019050919050565b6000612fd460168361370e565b9150612fdf82613bf3565b602082019050919050565b6000612ff760158361370e565b915061300282613c1c565b602082019050919050565b600061301a60148361370e565b915061302582613c45565b602082019050919050565b600061303d60098361370e565b915061304882613c6e565b602082019050919050565b600061306060078361370e565b915061306b82613c97565b602082019050919050565b6000613083600f8361370e565b915061308e82613cc0565b602082019050919050565b60006130a660128361370e565b91506130b182613ce9565b602082019050919050565b60006130c9600b8361370e565b91506130d482613d12565b602082019050919050565b6000610160830160008301516130f860008601826132ba565b50602083015161310b6020860182612cc6565b50604083015184820360408601526131238282612e99565b9150506060830151848203606086015261313d8282612d33565b91505060808301516131526080860182612cc6565b5060a083015161316560a08601826132ba565b5060c083015161317860c08601826132ba565b5060e083015184820360e08601526131908282612cd5565b9150506101008301516131a76101008601826132ba565b506101208301516131bc610120860182612e7b565b506101408301516131d16101408601826132ba565b508091505092915050565b600060a0830160008301516131f460008601826132ba565b50602083015161320760208601826132ba565b506040830151848203604086015261321f8282612e99565b91505060608301516132346060860182612e8a565b50608083015161324760808601826132ba565b508091505092915050565b60a0820160008201516132686000850182612e7b565b50602082015161327b60208501826132ba565b50604082015161328e60408501826132ba565b5060608201516132a160608501826132ba565b5060808201516132b46080850182612e7b565b50505050565b6132c381613910565b82525050565b6132d281613910565b82525050565b600060208201905081810360008301526132f28184612da8565b905092915050565b6000602082019050818103600083015261331381612ed2565b9050919050565b6000602082019050818103600083015261333381612ef5565b9050919050565b6000602082019050818103600083015261335381612f18565b9050919050565b6000602082019050818103600083015261337381612f3b565b9050919050565b6000602082019050818103600083015261339381612f5e565b9050919050565b600060208201905081810360008301526133b381612f81565b9050919050565b600060208201905081810360008301526133d381612fa4565b9050919050565b600060208201905081810360008301526133f381612fc7565b9050919050565b6000602082019050818103600083015261341381612fea565b9050919050565b600060208201905081810360008301526134338161300d565b9050919050565b6000602082019050818103600083015261345381613030565b9050919050565b6000602082019050818103600083015261347381613053565b9050919050565b6000602082019050818103600083015261349381613076565b9050919050565b600060208201905081810360008301526134b381613099565b9050919050565b600060208201905081810360008301526134d3816130bc565b9050919050565b600060208201905081810360008301526134f481846130df565b905092915050565b600060a0820190506135116000830184613252565b92915050565b600060208201905061352c60008301846132c9565b92915050565b600060808201905061354760008301876132c9565b81810360208301526135598186612e1d565b9050818103604083015261356d8185612e1d565b905081810360608301526135818184612e1d565b905095945050505050565b60006135966135a7565b90506135a2828261398e565b919050565b6000604051905090565b600067ffffffffffffffff8211156135cc576135cb613a7b565b5b602082029050602081019050919050565b600067ffffffffffffffff8211156135f8576135f7613a7b565b5b61360182613ac3565b9050602081019050919050565b6000819050602082019050919050565b6000819050602082019050919050565b6000819050602082019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b600081519050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b6000602082019050919050565b6000602082019050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b600061372a82613910565b915061373583613910565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561376a576137696139bf565b5b828201905092915050565b600061378082613910565b915061378b83613910565b92508261379b5761379a6139ee565b5b828204905092915050565b60006137b182613910565b91506137bc83613910565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156137f5576137f46139bf565b5b828202905092915050565b600061380b826138e6565b9150613816836138e6565b9250827f800000000000000000000000000000000000000000000000000000000000000001821260008412151615613851576138506139bf565b5b827f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff018213600084121615613889576138886139bf565b5b828203905092915050565b600061389f82613910565b91506138aa83613910565b9250828210156138bd576138bc6139bf565b5b828203905092915050565b60006138d3826138f0565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b8381101561394757808201518184015260208101905061392c565b83811115613956576000848401525b50505050565b6000600282049050600182168061397457607f821691505b6020821081141561398857613987613a1d565b5b50919050565b61399782613ac3565b810181811067ffffffffffffffff821117156139b6576139b5613a7b565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f596f7520617265206e6f74205265706f72746572210000000000000000000000600082015250565b7f596f7520646964206e6f74204372656174652100000000000000000000000000600082015250565b7f486173206265656e207265706f72746564000000000000000000000000000000600082015250565b7f596f75206861766520726563656976656420746865207072697a652100000000600082015250565b7f546865206576656e74206973206e6f74206f7665720000000000000000000000600082015250565b7f596f7520646964206e6f7420766f746521000000000000000000000000000000600082015250565b7f5265706f7274657220646f6573206e6f74206578697374210000000000000000600082015250565b7f44697361626c65206f74686572206f7074696f6e732100000000000000000000600082015250565b7f496e73756666696369656e742062616c616e6365210000000000000000000000600082015250565b7f596f752070726564696374206661696c75726521000000000000000000000000600082015250565b7f6e6f6e2d6f704944210000000000000000000000000000000000000000000000600082015250565b7f6e6f6e2d49442100000000000000000000000000000000000000000000000000600082015250565b7f796f752061726520437265617465640000000000000000000000000000000000600082015250565b7f546865206576656e74206973206f766572210000000000000000000000000000600082015250565b7f556e7265706f7274656421000000000000000000000000000000000000000000600082015250565b613d44816138c8565b8114613d4f57600080fd5b50565b613d5b81613910565b8114613d6657600080fd5b5056fea2646970667358221220354eaa0201bdd874184279168643371995a5b166d8161181db2f5db25107344c64736f6c63430008070033"
	Contracts.deploy({
		data:data
	}).send({
		from: '0x059ba9d375b418bf66d99c35e5a24b55fb2dd1ca',
		gas: 1500000,
		gasPrice: '100000'
	}), function (err, res) {
		console.log(res);
		console.log('上链成功');
	}
}

function CreatePlayer() {
	return Contracts.methods.CreatePlayer().send({ from: Address })
}

function InitiateEvent(content, option, Validity, addr) {
	return Contracts.methods.InitiateEvent(content, option, Validity, addr).send({ from: Address })
}

function Vote(id, option, finance) {
	return Contracts.methods.Vote(id, option, finance).send({ from: Address })
}

function Report(id, option) {
	return Contracts.methods.Report(id, option).send({ from: Address })
}

function Reward(id) {
	return Contracts.methods.Reward(id).send({ from: Address })
}

function getTotalEvent() {
	return Contracts.methods.getTotalEvent().call({ from: Address })
}

function getEvent(id) {
	return Contracts.methods.getEvent(id).call({ from: Address })
}

function getEventOptionInfo(id, option) {
	return Contracts.methods.getEventOptionInfo(id, option).call({ from: Address })
}

function getPlayer(addr = Address) {
	console.log('传的' + addr);
	return Contracts.methods.getPlayer(addr).call({ from: Address })
}

function getVote(id, addr = Address) {
	return Contracts.methods.getVote(id, addr).call({ from: Address })
}

function getPlayerLogs(addr = Address) {

	return Contracts.methods.getPlayerLogs(addr).call({ from: Address })
}

export {  //关键
	WEB3,
	Connection,
	CreatePlayer,
	InitiateEvent,
	Vote,
	Report,
	Reward,
	getTotalEvent,
	getEvent,
	getEventOptionInfo,
	getPlayer,
	getVote,
	getPlayerLogs,
	shang
}
